<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>三角形最小路径和</title>
</head>
<body>
  <script>
    function fn(triangle) {
      const row = triangle.length;
      if (row === 0) {
        return 0;
      }
      for (let i = row - 2; i >= 0; i--) {
        for (let j = 0, col = triangle[i].length; j < col; j++) {
          let min = Math.min(triangle[i + 1][j], triangle[i + 1][j + 1]);
          triangle[i][j] += min;
        }
      }
      return triangle[0][0]
    }
    console.log(fn([[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]]))
  </script>
</body>
</html>